
* replicates Table A2 in the online appendix

clear *

/*-----------------------------------------------------------------------------*/
/* Current Population Survey (March 2016 file) */
/*-----------------------------------------------------------------------------*/

use cps2016, clear

* drop minors
drop if a_age < 18

* randomly select one person per household
set seed 7
gen random = runiform()
sort h_seq random
by h_seq: egen rank = rank(random)
by h_seq: gen first = (rank == 1)
by h_seq: egen all = total(first)
tab all
assert r(r) == 1
drop all first
keep if rank == 1

gen weight = a_fnlwgt*1/.01

* top 5% 
_pctile htotval [pweight = a_fnlwgt], p(95)
local e95 = r(r1)
keep if htotval >= `e95'

* some recoding of sector information
drop if a_mjind == 0
* combine manufacturing and mining
recode a_mjind (2 = 4), gen(sector)
* combine professional and other services
recode sector (12 = 9)
lab val sector a_mjind
decode sector, gen(sector1)
replace sector1 = "Agriculture" if sector1 == "Agriculture, forestry, fishing, and hunting"
drop sector
rename sector1 sector

tab sector [fw=weight], gen(sector_)
local max = r(r)
mat mat = J(`max',1,.)
forval i = 1/`max' {
	mean sector_`i' [pw=a_fnlwgt]
	mat tab = r(table)
	local b = tab[1,1]
	mat mat[`i',1] = `b'
	drop sector_`i'
	}

/*-----------------------------------------------------------------------------*/
/* Our YouGov survey */
/*-----------------------------------------------------------------------------*/

use survey, clear

keep if incomeall >= 13
gen count = 1
collapse (count) count, by(sector)
drop if sector == ""
egen total = total(count)
gen yougov = count/total*100
drop count total
svmat mat
replace mat1 = mat1*100
rename mat1 cps
gsort -cps
order cps, before(yougov)

mkmat cps yougov, matrix(sector)

* create table
frmttable, statmat(sector) substat(0) sdec(1,1) ///
	rtitles("Professional and business services" \ ///
			"Education and health services" \ ///
			"Financial activities" \ ///
			"Wholesale and retail trade" \ ///
			"Manufacturing" \ ///
			"Leisure and hospitality" \ ///
			"Public administration" \ ///
			"Construction" \ ///
			"Transportation and utilities" \ ///
			"Information" \ ///
			"Agriculture") ///
			ctitles("","CPS 2016","Our survey")
